<?php

namespace App\Http\Controllers\Traits;

use Dingo\Api\Http\Response;
use Illuminate\Validation\ValidationException;

trait StoreResource
{
    /**
     * Resource store metho
     *
     * @return false|string
     * @throws ValidationException
     */
    public function store()
    {
        // todo 验证咋格式化attributes的
        $data = $this->validatedAndGetInput(
            $this->try('rules', []),
            $this->try('attributes', [])
        );

        $this->try('creating',$data);

        $model = $this->model->create($data);

        $this->try('created',$model);


        return $this->success();
    }
}
